%\documentclass[leqno,handout,9pt]{beamer} %handout
\documentclass[10pt]{beamer}

%\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade}
\usepackage{amsmath,amssymb,amsfonts,amsthm,latexsym}
\usepackage{mathabx}
\usepackage{graphicx,rotating}
\usepackage[latin1]{inputenc}
\usepackage{colortbl,fancybox}
\usepackage{array,alltt,verbatim,url}
\usepackage{epsfig}
%\usepackage{bm}               % bold math, für \bm{}
\usepackage{lmodern}
\usepackage[boxed, linesnumbered, lined]{algorithm2e}
\usepackage{url}
\usepackage{listings}

%Arguments for algorithms
%\IncMargin{1.5em}
\SetAlFnt{\footnotesize\sf}
\SetArgSty{textit}


\usepackage{subfigure}
\usepackage{ulem}

% Language Definitions for Turtle
\definecolor{olivegreen}{rgb}{0.2,0.8,0.5}
\definecolor{grey}{rgb}{0.5,0.5,0.5}
\lstdefinelanguage{ttl}{
basicstyle=\tiny,
sensitive=true,
morecomment=[l][\color{grey}]{@},
moredelim=[il]{\%},
moredelim=[il]{+},,
morestring=[b][\color{blue}]\",
}
\lstdefinelanguage{ttl2}{
basicstyle=\tiny,
sensitive=true,
morecomment=[l][\color{grey}]{@},
moredelim=[il][\color{red}]{\%},
moredelim=[il][\color{darkgreen}]{+},,
morestring=[b][\color{blue}]\",
}

%\usepackage{algorithm}
%\usepackage{algorithmic}

\newcommand{\argmax}{\operatornamewithlimits{argmax}}
\newcommand{\map}{\mathcal{M}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Try the class options [notes], [notes=only], [trans], [handout],
% [red], [compress], [draft], [class=article] and see what happens!


% For a green structure color use:
%\colorlet{structure}{yellow!50!red}

%\mode<article> % only for the article version
%{
%  \usepackage{beamerbasearticle}
%  \usepackage{fullpage}
%  \usepackage{hyperref}
%}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\mode<article> % only for the article version
%{
  %\usepackage{fullpage}
  %\usepackage{hyperref}
%}

\mode<presentation>
{
  %\setbeamertemplate{background canvas}[vertical shading][bottom=purple!10,top=yellow!10]
  \setbeamertemplate{navigation symbols}{}
  %\usetheme{Boadilla}
  %\useoutertheme{shadow}
  \usetheme[compress]{Berlin}
  %\usecolortheme{whale}
  %\usefonttheme[onlysmall]{structurebold}
  \usefonttheme{default}
  \setbeamercovered{invisible}
}

   \bibliographystyle{plain}

%\beamertemplateshadingbackground{red!10}{yellow!10}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Some abbreviations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\parindent 0mm

\def\colorize<#1>{\temporal<#1>{\color{gray}}{\color{black}}{\color{gray}}}

\definecolor{darkred}{rgb}{0.8,0.1,0.1}
\definecolor{darkgreen}{rgb}{0.2,0.6,0.2}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Use some nice templates
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\beamertemplateshadingbackground{blue!10}{structure!10} %\beamertemplatetransparentcovereddynamic
\beamertemplateballitem \beamertemplatenumberedballsectiontoc

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following info should normally be given in your main file:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\mybox}[1]{\Ovalbox{\parbox[]{\textwidth}{#1}}}
\newcommand{\ra}{\rightarrow}
  \newcommand{\Ra}{\Rightarrow}
  \newcommand{\La}{\Leftarrow}
  \newcommand{\la}{\leftarrow}
  \newcommand{\lr}{\leftrightarrow}
  \newcommand{\LR}{\Leftrightarrow}

\title{A Direct Mapping of Relational Data to RDF \\ \cite{2012rdbmapping} \cite{2012Sequeda}}
\institute{Semantic Web Technologies}
\author{Albin Ahmeti and Wolfgang Fischl}
\date{July 4th, 2012}

\begin{document}
\begin{frame}
  \titlepage
\end{frame}


\section{Introduction}
\subsection{}

\begin{frame}
 \frametitle{Introduction}
 \begin{itemize}
  \item Relational data everywhere on the web
  \item Convert this data into RDF in order to
  \begin{itemize}
   \item query the data with SPARQL
   \item extend the data
   \item connect the data
  \end{itemize}
 \pause
 \vfill
  \item create a mapping from relational databases to RDF
  \item mapping should
  \begin{itemize}
   \item convert structure and data
   \item have some properties
  \end{itemize}
 \end{itemize}
\end{frame}

\begin{frame}
 \frametitle{Literature}
 \bibliography{swt2012}
\end{frame}

\frame{\frametitle{Outline} \tableofcontents}

\section{A direct mapping description}
\subsection{}

\begin{frame}
 \frametitle{A first example}
 \begin{columns}[t]
 \column{.45\textwidth}
 \begin{block}{Course}
 \begin{tabular}{|l|l|l|}
  \hline
  \textit{PK}  & & $\ra$ \textit{Dept(DID)} \\ \hline
  \multicolumn{1}{|c|}{\textbf{CID}} & \multicolumn{1}{c|}{\textbf{Name}} & \multicolumn{1}{c|}{\textbf{Code}} \\ \hline
  100 & SWT & 10 \\ \hline
 \end{tabular}
 \end{block}
 \begin{block}{Dept}
 \begin{tabular}{|l|l|}
  \hline
  \textit{PK}  & \\ \hline
  \multicolumn{1}{|c|}{\textbf{DID}} & \multicolumn{1}{c|}{\textbf{Name}} \\ \hline
  10 & DBAI \\ \hline
 \end{tabular}
 \end{block}
 \column{.55\textwidth}
 \begin{block}{direct graph}
   \lstinputlisting[breaklines=true,language=ttl]{ex1.ttl}
 \end{block}
 \end{columns}
\end{frame}

\begin{frame}
 \frametitle{Multicolumn primary keys}
 \begin{columns}[t]
 \column{.52\textwidth}
 \begin{block}{Student}
 \begin{tabular}{|l|l|}
  \hline
  \textit{PK}  &  \\ \hline
  \multicolumn{1}{|c|}{\textbf{SID}} & \multicolumn{1}{c|}{\textbf{Name}} \\ \hline
  1 & Albin \\ \hline
  2 & Wolfgang \\ \hline
 \end{tabular}
 \end{block}
 \begin{block}{Enrolled}
 \begin{tabular}{|l|l|}
  \hline
  \multicolumn{1}{|c|}{$\ra$ Studen(SID)} & \multicolumn{1}{c|}{$\ra$ Course(CID)} \\ \hline
  \multicolumn{2}{|c|}{\textit{PK}}  \\ \hline
  \multicolumn{1}{|c|}{\textbf{SID}} & \multicolumn{1}{c|}{\textbf{CID}} \\ \hline
  1 & 100 \\ \hline
  2 & 100 \\ \hline
 \end{tabular}
 \end{block}
 \column{.48\textwidth}
 \begin{block}{direct graph}
   \lstinputlisting[breaklines=true,language=ttl]{ex2.ttl}
 \end{block}
 \end{columns}
\end{frame}

\begin{frame}
 \frametitle{Empty primary key}
 \begin{block}{Tweets}
 \begin{center}
 \begin{tabular}{|l|l|l|}
  \hline
  $\ra$ \textit{Student(SID)} &  & \\ \hline
  \multicolumn{1}{|c|}{\textbf{tweeter}} & \multicolumn{1}{c|}{\textbf{when}} & \multicolumn{1}{c|}{\textbf{text}} \\ \hline
  1 & 2010-08-30T01:33 & I really like RDF! \\ \hline
  1 & 2010-08-30T09:01 & RDB2RDF is even more fun! \\ \hline
 \end{tabular}
 \end{center}
 \end{block}
 \begin{block}{direct graph}
    \lstinputlisting[breaklines=true,language=ttl]{ex3.ttl}
 \end{block}
\end{frame}

\section{Direct Graph Definition}
\subsection{}

\begin{frame}
 \frametitle{Basic Definitions}
 \begin{block}{percent-encode}
 Replace a string with the IRI-safe form
 
 \textbf{Example}: "Hello World!" $\ra$ "Hello\%20World\%21"
 \end{block}
 
 \begin{block}{row node}
 \begin{itemize}
  \item Table has a primary key: the row node is a relative IRI containing the table name and all primary key columns
  \item Table has no primary key: a fresh blank node
 \end{itemize}
 \textbf{Example}: \texttt{<Student/SID=1>}
 \end{block}
 
 \begin{block}{table IRI}
  the relative IRI consisting of the percent-encoded form of the table name
  
  \textbf{Example}: \texttt{<Student>}
 \end{block}
\end{frame}



\begin{frame}
 \frametitle{Basic Definitions}
 \begin{block}{literal property IRI}
 concatenation of the percent-encoded form of the table name, the hash character '\#' and the percent-encoded form of the column name
 
 \textbf{Example}: \texttt{<Student\#SID>}
 \end{block}
 
 \begin{block}{reference property IRI}
 concatenation of the percent-encoded form of the table name, the string "ref-", for each column in the foreign key, the percent-encoded form of the column names
 
 \textbf{Example}: \texttt{<Course\#ref-Code>}
 \end{block}
\end{frame}

\subsection{}

\begin{frame}
 \frametitle{Definition Direct Graph}
 \begin{block}{direct graph}
 the union of the table graphs for each table in a database schema
 \end{block}
 
 \begin{block}{table graph}
 the union of the row graphs for each row in a table
 \end{block}
 
 \begin{block}{row graph}
 \begin{itemize}
  \item the row type triple
  \item a reference triple
  \item a literal triple
 \end{itemize}

 \end{block}
\end{frame}

\begin{frame}
 \frametitle{Definition Direct Graph}
 \begin{block}{row type triple}
  \begin{itemize}
   \item \textit{subject}: the row node of the row
   \item \textit{predicate}: the RDF IRI \texttt{rdf:type}
   \item \textit{object}: the table IRI for the table name
  \end{itemize}
 \end{block}
 
 \begin{block}{Example}
    \texttt{<Student/SID=1> rdf:type <Student> .}
 \end{block}


\end{frame}

\begin{frame}
 \frametitle{Definition Direct Graph}
 \begin{block}{literal triple}
 \begin{itemize}
   \item \textit{subject}: the row node of the row
   \item \textit{predicate}: the literal property IRI for the column
   \item \textit{object}: the RDF literal representation of the columns value
  \end{itemize}
 \end{block}
 
 \begin{block}{Example}
     \texttt{<Student/SID=1> <Student\#SID> 1 .}
 \end{block}
\end{frame}

\begin{frame}
 \frametitle{Definition Direct Graph}
 \begin{block}{reference triple}
  \begin{itemize}
   \item \textit{subject}: the row node of the row
   \item \textit{predicate}: the reference property IRI for the columns
   \item \textit{object}: the row node of the referenced row
  \end{itemize}
 \end{block}
 
 \begin{block}{Example}
     \texttt{<Course/CID=100> <Course\#ref-Code> <Dept/DID=10> .}
 \end{block}
\end{frame}

\section{Differences to $\mathcal{DM}$ in \cite{2012Sequeda}}
\subsection{}

\begin{frame}
  \frametitle{Direct Mapping - $\mathcal{DM}$}
  \begin{itemize}
   \item Mapping RDB (+schema constraints) to OWL DL in automatic way using finite Datalog rules
   \item Inspired by the draft of W3C Direct Mapping standard
   \item Imposes some properties:
   \begin{itemize}
     \item \textbf{Fundamental properties}
     \begin{itemize}
       \item Information preservation
       \item Query preservation
     \end{itemize}
     \item \textbf{Desirable properties}
     \begin{itemize}
       \item Monotonicity
       \item Semantic preservation
     \end{itemize}
   \end{itemize}
  \end{itemize}
\end{frame}


\begin{frame}
 \frametitle{A first example - Recap}
 \begin{columns}[t]
 \column{.45\textwidth}
 \begin{block}{Course}
 \begin{tabular}{|l|l|l|}
  \hline
  \textit{PK}  & & $\ra$ \textit{Dept(DID)} \\ \hline
  \multicolumn{1}{|c|}{\textbf{CID}} & \multicolumn{1}{c|}{\textbf{Name}} & \multicolumn{1}{c|}{\textbf{Code}} \\ \hline
  100 & SWT & 10 \\ \hline
 \end{tabular}
 \end{block}
 \begin{block}{Dept}
 \begin{tabular}{|l|l|}
  \hline
  \textit{PK}  & \\ \hline
  \multicolumn{1}{|c|}{\textbf{DID}} & \multicolumn{1}{c|}{\textbf{Name}} \\ \hline
  10 & DBAI \\ \hline
 \end{tabular}
 \end{block}
 \column{.55\textwidth}
 \begin{block}{direct graph}
   \lstinputlisting[breaklines=true,language=ttl]{ex1.ttl}
 \end{block}
 \end{columns}
\end{frame}

\begin{frame}
 \frametitle{A first example - $\mathcal{DM}$}
 \begin{columns}[t]
 \column{.45\textwidth}
 \begin{block}{direct graph}
   \lstinputlisting[breaklines=true,language=ttl2]{ex1.ttl}
 \end{block}
 \column{.55\textwidth}
 \begin{block}{$\mathcal{DM}$}
   \lstinputlisting[breaklines=true,language=ttl2]{ex4.ttl}
 \end{block}
 \end{columns}
\end{frame}

\begin{frame}
 \frametitle{Binary relations in $\mathcal{DM}$}
 \begin{columns}[t]
 \column{.52\textwidth}
 \begin{block}{Student}
 \begin{tabular}{|l|l|}
  \hline
  \textit{PK}  &  \\ \hline
  \multicolumn{1}{|c|}{\textbf{SID}} & \multicolumn{1}{c|}{\textbf{Name}} \\ \hline
  1 & Albin \\ \hline
  2 & Wolfgang \\ \hline
 \end{tabular}
 \end{block}
 \begin{block}{Enrolled}
 \begin{tabular}{|l|l|}
  \hline
  \multicolumn{1}{|c|}{$\ra$ Studen(SID)} & \multicolumn{1}{c|}{$\ra$ Course(CID)} \\ \hline
  \multicolumn{2}{|c|}{\textit{PK}}  \\ \hline
  \multicolumn{1}{|c|}{\textbf{SID}} & \multicolumn{1}{c|}{\textbf{CID}} \\ \hline
  1 & 100 \\ \hline
  2 & 100 \\ \hline
 \end{tabular}
 \end{block}
 \column{.48\textwidth}
 \begin{block}{direct graph}
   \lstinputlisting[breaklines=true,language=ttl]{ex2.ttl}
 \end{block}
 \end{columns}
\end{frame}

\begin{frame}
 \frametitle{Binary relations in $\mathcal{DM}$}
 \begin{columns}[t]
 \column{.5\textwidth}
 \begin{block}{direct graph}
   \lstinputlisting[breaklines=true,language=ttl2]{ex2.ttl}
 \end{block}
 \column{.5\textwidth}
 \begin{block}{$\mathcal{DM}$}
   \lstinputlisting[breaklines=true,language=ttl2]{ex5.ttl}
 \end{block}
 \end{columns}
\end{frame}

\section{Query preservation}
\subsection{}

\begin{frame}
 \frametitle{Query Preservation}
 \begin{itemize}
\item Translating SQL to SPARQL seamlessly, i.e. query preservation between
a database and an ontology
\item Let's do it by Example
\item Relational algebra query: \end{itemize}
\begin{quote}%{}
\begin{center}
{\footnotesize $\sigma_{Name=Juan}(STUDENT)\bowtie ENROLLED$}
\par\end{center}{\footnotesize \par}\end{quote}%{}
\begin{itemize}
\item Translated SPARQL query ? 
\item Done inductively!
\end{itemize}
\end{frame}

\begin{frame}[fragile]
 \frametitle{Query Preservation (cont.)}
 \begin{quote}%{}
\begin{center}
{\footnotesize $\sigma_{Name=Juan}({\color{red}STUDENT})\bowtie ENROLLED$}
\par\end{center}{\footnotesize \par}\end{quote}%{}
\begin{itemize}
\item Relation STUDENT is non-binary relation, hence the following SPARQL
construct is used:\end{itemize}


\begin{center}
\lstset{language=SPARQL,morekeywords={AND}}
\begin{lstlisting}
 SELECT ?SID, ?NAME 
   WHERE { ?X rdf:type :Student 
           OPT { ?X :Student#SID ?SID } 
           OPT { ?X :Student#Name ?NAME  }
         }
\end{lstlisting}
\end{center}


\end{frame}


\begin{frame}[fragile]
 \frametitle{Query Preservation (cont.)}
 \begin{quote}%{}
\begin{center}
{\footnotesize $\sigma_{{\color{red}Name=Juan}}({\color{red}STUDENT})\bowtie ENROLLED$}
\par\end{center}{\footnotesize \par}\end{quote}%{}
\begin{itemize}
\item Filter tuples that fulfill the restriction: Name=Juan\end{itemize}

\begin{center}
\lstset{language=SPARQL,morekeywords={AND}}
\begin{lstlisting}
 SELECT ?SID, ?NAME 
   WHERE { ?X rdf:type :Student 
           OPT { ?X :Student#SID ?SID } 
           OPT { ?X :Student#Name ?NAME }
           FILTER ( ?NAME = Juan )
         }
\end{lstlisting}
\end{center}

\end{frame}

\begin{frame}[fragile]
 \frametitle{Query Preservation (cont.)}
 \begin{quote}%{}
\begin{center}
{\footnotesize $\sigma_{Name=Juan}(STUDENT)\bowtie{\color{red}ENROLLED}$}
\par\end{center}{\footnotesize \par}\end{quote}%{}
\begin{itemize}
\item Relation ENROLLED is a binary relation, hence the following SPARQL
construct is used:\end{itemize}

\begin{center}
\lstset{language=SPARQL,morekeywords={AND}}
\begin{lstlisting}
 SELECT ?SID, ?CID 
   WHERE { ?T1 :Enrolled#SID,CID,SID,CID ?T2 AND
           ?T1 :Student#SID ?SID AND
           ?T2 :Course#CID ?CID AND
         }
\end{lstlisting}
\end{center}
\end{frame}

\begin{frame}
 \frametitle{Query Preservation (cont.)}
 \begin{quote}%{}
\begin{center}
{\footnotesize $\sigma_{Name=Juan}(STUDENT){\color{red}\bowtie}ENROLLED$}
\par\end{center}{\footnotesize \par}\end{quote}%{}
\begin{itemize}
\item Join operator, performing AND among the obtained SPARQL queries\end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{$\sigma_{Name=Juan}(STUDENT){\color{red}\bowtie}ENROLLED$}
\begin{center}
\lstset{basicstyle=\scriptsize,language=SPARQL,morekeywords={AND}}
\begin{lstlisting}
SELECT ?SID, ?NAME, ?CID
WHERE {
 { SELECT ?SID, ?NAME 
   WHERE { ?X rdf:type :Student 
           OPT { ?X :Student#SID ?SID  }
           OPT { ?X :Student#Name ?NAME  }
           FILTER ( ?NAME = Juan )
         } 
   FILTER (bound(?SID))
 }
   AND
 {
   SELECT ?SID, ?CID 
   WHERE { ?T1 :Enrolled#SID,CID,SID,CID ?T2 AND
           ?T1 :Student#SID ?SID AND
           ?T2 :Course#CID ?CID AND
         }
   FILTER (bound(?SID))
 }
}
\end{lstlisting}
\end{center}
\end{frame}


\section{Conclusion}
\subsection{}

\begin{frame}
 \frametitle{Conclusion}
 \begin{itemize}
\item We've presented two approaches of directly mapping RDBs to ontologies

\begin{itemize}
\item In the first approach RDBs are mapped to RDF following RDB2RDF Working
group
\item In the second approach RDBs are mapped to OWL DL following Sequeda
et al. paper
\end{itemize}
\item In both cases integrity constraints are taken into consideration 
\item The second approach has its advantage as 

\begin{itemize}
\item It uses the expressivity of OWL DL

\begin{itemize}
\item Classes, 
\item ObjectProperties with Domain and Range restriction,
\item DatatypeProperties with Domain restriction
\end{itemize}
\item Further fundamental and desirable properties are elaborated
\end{itemize}
\item We've showed here the query preservation property
\end{itemize}
\end{frame}






\begin{frame}
 \frametitle{The End}
 \begin{center}
{\begin{huge}The End\end{huge}}
 \vfill
 {\begin{Large}Thank you for your attention!\end{Large}}
\end{center}
\end{frame}


\end{document}



%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 
